event.js ➔ ???   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
c 2
b 0
f 0
nc 1
dl 0
loc 20
nop 1
rs 9.4

1 Function

Rating   Name   Duplication   Size   Complexity  
A event.js ➔ ... ➔ ??? 0 4 1
1
import { getMetricsInstance } from './init';
2
3
export const createEventMetrics = ({ service, operation, action }) => {
4
	const metrics = getMetricsInstance();
5
	if (metrics === undefined) {
6
		throw Error(`auto metrics instance needs to be initialised first`);
7
	}
8
	const serviceRoot = `service.${service}.action.${action}`;
9
	const operationRoot = `operation.${operation}.action.${action}`;
10
	const countOne = path => {
11
		metrics.count(`${serviceRoot}.${path}`, 1);
12
		metrics.count(`${operationRoot}.${path}`, 1);
13
	};
14
	return {
15
		start: () => countOne('state.start'),
16
		success: () => countOne('state.success'),
17
		failure: e => {
18
			countOne(`state.failure.category.${e.category}.status.${e.status}`);
19
			countOne(`state.failure.category.${e.category}.type.${e.type}`);
20
		},
21
	};
22
};
23
24
export const metricsEvent = ({ service, operation, action }) => {
25
	const event = createEventMetrics({ service, operation, action });
26
	event.start();
27
	return event;
28
};
29